package sf.tools;

import java.time.LocalDate;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Date;

public class DateUtils {
    /**
     * LocalDate转Date
     * @param localDate
     * @return
     */
    public static Date localDate2Date(LocalDate localDate) {
        if (null == localDate) {
            return null;
        }
        ZonedDateTime zonedDateTime = localDate.atStartOfDay(ZoneId.systemDefault());
        return Date.from(zonedDateTime.toInstant());
    }

    /**
     * 获取年月日的日期
     * @param date
     * @return
     */
    public static Date getDay(Date date) {
        long time = date.getTime();
        long dayTime = time - (time % (24 * 3600 * 1000));
        return new Date(dayTime);
    }

    /**
     * @param time
     * @return
     */
    public static Date getDay(long time) {
        long dayTime = time - (time % (24 * 3600 * 1000));
        return new Date(dayTime);
    }
}
